<?php
class ContactController extends Sosweb_Controller_Action
{
	function init()
	{
		parent::init();
		$this->logger->info('Inicjalizacja strony kontaktu z sosweb.pl przez użytkownika z IP: '.$_SERVER['REMOTE_ADDR']);
	}

	function indexAction()
	{
		$request = clone $this->getRequest();
        $request->setActionName('contact');
        $this->_helper->actionStack($request);

        $request = clone $this->getRequest();
        $request->setActionName('form');
        $this->_helper->actionStack($request);		
	}
	
	function contactAction()
	{
		$this->view->getHelper('HeadLink')->appendStylesheet($this->view->baseUrl.'/public/styles/contact.contact.css');	
	}
	
	function formAction()
	{
		$this->view->getHelper('HeadLink')->appendStylesheet($this->view->baseUrl.'/public/styles/contact.form.css');
	}
	
	function sendmailAction()
	{
		$this->_helper->layout()->disableLayout();
		$this->_helper->viewRenderer->setNoRender();

		$name = $this->getRequest()->getParam("name_input");
		$email = $this->getRequest()->getParam("email_input");
		$title = $this->getRequest()->getParam("title_input");
		$message = $this->getRequest()->getParam("message_input");
		
		$this->logger->info('Wysyłanie wiadomości '.$title.' od '.$name);
		
		try
		{
			$mail = new Zend_Mail('utf-8');
			$mail->setBodyText($message)
			    ->setFrom($email, $name)
			    ->addTo('web@sosweb.pl', 'SosWeb.pl')
			    ->addCc('radoslaw.wojciechowski@gmail.com', 'WebMaster')
			    ->setSubject($title)
			    ->send();
			
			echo 'true';
		}
		catch(Zend_Mail_Exception $mex)
		{
			$this->logger->error($mex->getMessage());
			echo 'false';
		}
	}
}
?>